package sunlee.com;

/**
 * @author sunjulei
 * @date 2021/4/20.
 */
public class Code122_Simple {
    public static void main(String[] args) {
        int[] arrs = {7, 1, 5, 3, 6, 4};
        System.out.println(maxProfit(arrs));
    }

    /**
     * 收集所有的上坡，一定是利益最大化
     * @return
     */
    public static int maxProfit(int[] prices) {
        int sum = 0;
        for (int i = 0; i < prices.length - 1; i++) {
            if (prices[i] < prices[i + 1]) {
                sum += prices[i + 1] - prices[i];
            }
        }
        return sum;
    }
}
